import WeexNativeModule from "../../common/WeexNativeModule";
import ACApi from "../../common/http/ACApi";
import StringUtils from "../../common/util/StringUtils";
import JsonFilter from "../../common/util/JsonFilter";
import DateUtil from "../../common/util/DateUtil";
import AppConfig from "../../common/AppConfig";
let instance;
let taskcode;
let loginUser = {};
let isXinleiDoctor = false;
class EMNewRSControl{
    constructor(vue){
        instance = vue;
        this.getLoginUser();
    }
    getLoginUser(){
        let self = this;
        WeexNativeModule.getLoginUser(function (res) {
            let param = JSON.parse(res.loginUser);
            loginUser.id = param.id;
            loginUser.orgid = param.orgid;
            loginUser.name = param.username;
            loginUser.roleids = param.roleids;
            isXinleiDoctor = AppConfig.isXINLEIDoctor(loginUser);
            self.initData();
        })

    }
    initData(){
        let self = this;
        WeexNativeModule.getParam(function (res) {
            let param = JSON.parse(res.param);
            // WeexNativeModule.alert(param)
            if(param.isJustOpen){
                instance.canSave = false;
                let data = JSON.parse(param.data);
                instance.resData.DiagTreatModel.THROM_START_AGREE_TIME = data.THROM_START_AGREE_TIME;
                instance.resData.DiagTreatModel.THROM_SIGN_AGREE_TIME = data.THROM_SIGN_AGREE_TIME;
                instance.resData.DiagTreatModel.THROM_START_TIME_DT = data.THROM_START_TIME_DT;
                instance.resData.DiagTreatModel.THROM_END_TIME_DT = data.THROM_END_TIME_DT;
                instance.resData.DiagTreatModel.THROM_DRUG_TYPE_DT = data.THROM_DRUG_TYPE_DT;
                instance.resData.DiagTreatModel.THROM_DRUG_CODE_DT = data.THROM_DRUG_CODE_DT;
                instance.resData.DiagTreatModel.DIAGNOSIS_UNIT_CODE_DT = data.DIAGNOSIS_UNIT_CODE_DT;

            }else {
                instance.canSave = true;
                taskcode = param.taskcode;
            }
        })
    }

    selectedDateTime(type,defaulttime){
        if(! instance.canSave){
            return
        }
        let defaultdate;
        if(!StringUtils.isEmpty(defaulttime)){
            defaultdate = DateUtil.formatTime(
                new Date(defaulttime),'yyyy-MM-dd hh:mm');
        }else {
            defaultdate = DateUtil.formatTime(
                new Date(),'yyyy-MM-dd hh:MM');
        }
        WeexNativeModule.selectDateTime(defaultdate,false,true,true,true,true,false,
            false,'','',function (res) {
                let result = DateUtil.formatTime(
                     new Date(res.data), 'yyyy-MM-dd hh:mm');
                if(type == 0){
                    instance.resData.DiagTreatModel.THROM_START_AGREE_TIME = result;
                }
                if(type == 1){
                    instance.resData.DiagTreatModel.THROM_SIGN_AGREE_TIME = result;
                }
                if(type == 2){
                    instance.resData.DiagTreatModel.THROM_START_TIME_DT = result;
                }
                if(type == 3){
                    instance.resData.DiagTreatModel.THROM_END_TIME_DT = result;
                }
            });
    }
    saveData(){
        let content={};
        content = JsonFilter.filter(instance.resData.DiagTreatModel);
        content.ORDER_ID = taskcode;
        WeexNativeModule.addEMNode(JSON.stringify(content))
    }
    finish(){
        WeexNativeModule.finish();
    }
}
export default EMNewRSControl;